<?php
/**
 * Create By: PhpStorm
 * User: niechenguang
 * File: Circle.php
 * Date: 2017/1/2
 * Time: 23:13
 */

namespace app\api\model\page\note;

use app\api\model\dao\Note;
use app\api\model\dao\NotePraise;
use app\api\model\dao\NoteReplyPraise;
use app\api\model\dao\UpRank;
use app\library\Error;
use app\library\Flag;
use app\library\PageBase;
use think\Exception;
use think\Log;
use think\Validate;

class CancelReplyPraise extends PageBase
{

    private $objNote;
    private $objReplyPraise;

    public function __construct()
    {
        parent::__construct();

        $this->objNote = new Note();
        $this->objReplyPraise = new NoteReplyPraise();
    }

    /**
     * @param $param
     * @return array|bool
     * @DESC 验证接口字段
     */
    public function checkParam($param)
    {
        $rule = [
            'note_id' => 'require',
            'reply_id' => 'require',
        ];
        $msg = [
            'note_id.require' => '帖子id不能为空',
            'reply_id.require' => '评论id不能为空',
        ];

        $validate = new Validate($rule, $msg);
        $result = $validate->check($param);
        if (!$result) {
            return $validate->getError();
        }
        return '';
    }

    public function myExcute($param)
    {
        $ret = $this->checkToken($param);
        if (false === $ret) {
            throw new Exception('check token fail...', Error::ERR_NO_AUTH);
        }

        // 1、参数校验
        $ret = $this->checkParam($param);
        if ($ret) {
            return $this->getRes(Error::ERR_PARAM);
        }

        $ret = $this->objReplyPraise->cancelPraise($param['note_id'], $param['reply_id'], $this->user_id);
        if (false === $ret) {
            return $this->getRes(Error::ERR_SYS);
        }

        return $this->getRes();

    }
}
